package com.wutuo.aggragation.tag.controller;

import cn.apestar.core.base.BaseMessage;
import com.wutuo.tag.api.TagAPIService;
import com.wutuo.tag.api.request.TagRequest;
import com.wutuo.tag.api.response.TagResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 标签 <br>
 * 详细说明.
 * <p>
 * Copyright: Copyright (c) 2016年1月26日 下午10:21:39
 * <p>
 *
 * @author lvh
 * @version 1.0.0
 */
@RestController
@RequestMapping(value = "/tag", produces = "application/json")
public class TagController {

    private Logger logger = LoggerFactory.getLogger(TagController.class);

    @Autowired
    private TagAPIService tagService;

    /**
     * 新增标签
     *
     * @param request
     */
    @RequestMapping(value = "/addorUpdate", method = RequestMethod.POST)
    public Object create(
            @RequestBody @Valid TagRequest request) {

        tagService.addorUpdate(request);
        return new BaseMessage();
    }

    /**
     * 删除标签
     *
     * @param id
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
    public Object del(
            @PathVariable("id") Long id) {

        tagService.del(id);
        return new BaseMessage();
    }

    /**
     * 查询标签
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public List<TagResponse> list(
            @RequestBody TagRequest request) {

        return tagService.list(request);
    }

    /**
     * 查询标签根据用户
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/listByUserId", method = RequestMethod.POST)
    public List<TagResponse> listByUserId(@RequestBody TagRequest request) {

        return tagService.listByUserId(request);
    }
}
